Code
1 + 1[1] 2
Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see https://quarto.org.
When you click the Render button a document will be generated that includes both content and the output of embedded code. You can embed code like this:
1 + 1[1] 2
You can add options to executable code like this (the option #| echo:false is used at the top of the code chunk).
The echo: false option disables the printing of code (only output is displayed), so the chunk is not visible.
[1] 4
Snippets of code using different languages can be included. Here we make a set of R packages available for usage in R code chunks:
pkgs <- "
DT bslib leaflet plotly htmltools dplyr purrr
"
import <- function(x)
x |> trimws() |> strsplit("\\s+") |> unlist() |>
lapply(function(x) library(x, character.only = TRUE)) |>
invisible()
pkgs |> import()A chunk used here includes a KTH logo by generating a custom styles.css for the banner, which can be included in the quarto document.
# install the "ktheme" package which provides fonts and styling assets for KTH
# for example for use in static and dynamic plots
if (!"ktheme" %in% installed.packages())
devtools::install_github("KTH-Library/ktheme")
iuri <- knitr::image_uri(system.file(package="ktheme",
"extdata", "_extensions", "ktheme", "img", "kth_logo_white.png"))
# htmltools::img(
# src = iuri,
# alt = 'logo',
# style = 'position:absolute; top:0; right:0; padding:10px;',
# height = '120px'
# )
styles_css <-
".quarto-title-block .quarto-title-banner {
background-image: url('%s');
background-origin: content-box;
background-size: 120px;
background-position: right;
background-position-y: bottom;
background-repeat: no-repeat;
padding-left: 10px;
padding-right: 30px;
padding-top: 30px;
padding-bottom: 30 px;
}" |> sprintf(iuri)
message("Wrote background logo styles to styles.css")Wrote background logo styles to styles.css
readr::write_file(styles_css, "styles.css")We can include static or dynamic plots, for example using ggplot.
This is an example of a static plot using KTH graphical profile colors from ktheme.
This is an example of a interactive variant of the same plot.